﻿(function () {
    "use strict";

    WinJS.UI.Pages.define("/pages/register/register.html", {
        // This function is called whenever a user navigates to this page. It
        // populates the page elements with the app's data.
        ready: function (element, options) {
            // TODO: Initialize the page here.
            $('#-register-submin').click(function () {
                var _user = $('#-register-user').val().trim();
                var _pwd = $('#-register-pwd').val().trim();
                var _question = $('#-register-question').val().trim();
                var _answer = $('#-register-answer').val().trim();

                if (_user == '') {
                    $('#-register-error').text('User name can\'t be empty!');
                    return;
                }
                if (_pwd == '') {
                    $('#-register-error').text('Password can\'t be empty!');
                    return;
                }
                if (_question == '') {
                    $('#-register-error').text('Recover question can\'t be empty!');
                    return;
                }
                if (_answer == '') {
                    $('#-register-error').text('Recover answer can\'t be empty!');
                    return;
                }

                var _userStore = Ext.StoreMgr.lookup('SafeBox.Store.UserStore');
                _userStore.add({ user: _user, password: _pwd, question: _question, answer: _answer });
                _userStore.sync();
                WinJS.Navigation.navigate("/pages/home/home.html");

            });
        }
    });
})();
